package com.lyhengtongwl.zqsnews.utils;

import com.lyhengtongwl.zqsnews.App;
import com.lyhengtongwl.zqsnews.base.Constant;

/**
 * Created by Steven on 2019/1/24.
 */
public class UserUtils {
    //判断用户是否登录

    public static boolean checkLogin() {
        //发生变化  进行调试
        String accessToken = SPUtils.get(App.getContext(), Constant.CommonInfo.TOKEN, "") + "";
        String userId = SPUtils.get(App.getContext(), "userId", "") + "";
        return !"".equals(accessToken) && !"".equals(userId);

    }

    //检测本地token是否存在
    public static boolean isHaveToken() {
        String accessToken = SPUtils.get(App.getContext(), Constant.CommonInfo.TOKEN, "") + "";
        return !"".equals(accessToken);
    }


    //判断本地是否有UserId
    public static boolean isHaveUserId() {
        String userId = SPUtils.get(App.getContext(), "userId", "") + "";
        return !userId.equals("");
    }


    //判断本地是否有文章的randomCode
    public static boolean isHaveRandomCode() {
        String randomCode = SPUtils.get(App.getContext(), "random_code", "") + "";
        return !randomCode.equals("");
    }

    //判断本地是否存在shareCode
    public static boolean isHaveShareCode() {
        String shareCode = SPUtils.get(App.getContext(), "shareCode", "") + "";
        return !shareCode.equals("");
    }

    //清空用户信息  4003 和 4004的时候
    public static void clearUserInfo() {

        String uniqueIdentifier = SPUtils.get(App.getContext(), "uniqueIdentifier", "00:00:00:00:00:02") + "";
        String token = SPUtils.get(App.getContext(), Constant.CommonInfo.TOKEN, "") + "";
        String isCloseGuide = SPUtils.get(App.getContext(), "isCloseGuide", "") + "";
        SPUtils.clear(App.getContext());//清楚所有信息
        SPUtils.put(App.getContext(), "uniqueIdentifier", uniqueIdentifier);
        SPUtils.put(App.getContext(), "token", token);
        SPUtils.put(App.getContext(), "isCloseGuide", isCloseGuide);
//        SPUtils.remove(App.getContext(), Constant.CommonInfo.ACCESS_TOKEN);
//        SPUtils.remove(App.getContext(), Constant.CommonInfo.TOKEN);
    }

    public static void clearAllUserInfo() {
        String uniqueIdentifier = SPUtils.get(App.getContext(), "uniqueIdentifier", "00:00:00:00:00:02") + "";
        SPUtils.clear(App.getContext());//清楚所有信息
        SPUtils.put(App.getContext(), "uniqueIdentifier", uniqueIdentifier);
//        SPUtils.remove(App.getContext(), Constant.CommonInfo.ACCESS_TOKEN);
//        SPUtils.remove(App.getContext(), Constant.CommonInfo.TOKEN);
    }
}
